<?php
include 'header.php';
?>

<!----------------------------------------FIN de la  partie qui concerne le SLIDER ---------------------------------------->

</div>

</div>

<section>
	<colonne_centre>

		<?php

		include 'forum/connect.php';
	
		if (isset($_POST['submit'])) {
			$sql = "update users
				set user_tel= '".$_POST['user_tel']."'
				where user_id='".$_SESSION['user_id']."'";
	
			$result = mysql_query($sql);
			if(!$result){
				echo 'Internal error: the informations could not be updated';		
			}
			else{
				echo 'The changes were made successfully';	
			}
		}

		$name = $_SESSION['user_email'];
		$sql = "SELECT
			 *
			 FROM
			 users
			 WHERE
			 user_email = '" . mysql_real_escape_string($name) . "'";

		$result = mysql_query($sql);

		if (!$result) {
			//something went wrong, display the error
			echo 'Something went wrong while retrieving in the data. We apologize for that.';
			echo mysql_error();
			//debugging purposes, uncomment when needed
		} else {
			//the query was successfully executed, there are 2 possibilities
			//1. the query returned data, the user can be signed in
			//2. the query returned an empty result set, the credentials were wrong
			if (mysql_num_rows($result) == 0) {
				echo 'This is not a valid account id. Sorry about that.';
				$no_result = true;
			} else {
				//set the $_SESSION['signed_in'] variable to TRUE
				$_SESSION['signed_in'] = true;

				//we also put the user_id and user_email values in the $_SESSION, so we can use it at various pages
				while ($row = mysql_fetch_assoc($result)) {
					$_SESSION['user_id'] = $row['user_id'];
					$_SESSION['user_email'] = $row['user_email'];
					$_SESSION['user_level'] = $row['user_level'];
					$_SESSION['user_firstname'] = $row['user_name'];
					$_SESSION['user_lastname'] = $row['user_lastname'];
					$_SESSION['user_email'] = $row['user_email'];
					$_SESSION['user_function'] = $row['fonction'];
					$_SESSION['user_entreprise'] = $row['entreprise'];
					$_SESSION['user_tel'] = $row['user_tel'];
				}
			}
		}
		?>
	</colonne_centre>
	
	<form id="RegisterUserForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
		Change profile:	
		<p>
			First Name: <input value="<?php echo $_SESSION['user_firstname']?>" name="user_firstname" id="user_firstname" ?>
		</p>
		<p>
			Last Name: <input value="<?php echo $_SESSION['user_lastname']?>" name="user_lastname" id="user_lastname" ?>
		</p>
		<p>
			Email: <input value="<?php echo $_SESSION['user_email']?>" name="user_email" id="user_email" ?>
		</p>
		<p>
			Function: <input value="<?php echo $_SESSION['user_function']?>" name="user_function" id="user_function" ?>
		</p>
		<p>
			Entreprise: <input value="<?php echo $_SESSION['user_entreprise']?>" name="user_entreprise" id="user_entreprise" ?>
		</p>
		<p>
			Phone: <input value="<?php echo $_SESSION['user_tel']?>" name="user_tel" id="user_tel" ?>
		</p>
		<input type = "submit" name = "submit" required value = "Register">
	</form>
</section>
</div>

</div>
</body>
</html>
